package cn.iocoder.yudao.module.social.api.content;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.social.api.content.dto.ContentReqDTO;
import cn.iocoder.yudao.module.social.api.content.dto.ContentRespDTO;
import cn.iocoder.yudao.module.social.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;

/**
 * RPC 服务 - 内容管理
 *
 * @author 芋道源码
 */
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
@Tag(name = "RPC 服务 - 内容管理")
public interface ContentApi {

    String PREFIX = ApiConstants.PREFIX + "/content";

    @PostMapping(PREFIX + "/create")
    @Operation(summary = "创建内容")
    CommonResult<Long> createContent(@RequestBody ContentReqDTO reqDTO);

    @PutMapping(PREFIX + "/update")
    @Operation(summary = "更新内容")
    CommonResult<Boolean> updateContent(@RequestBody ContentReqDTO reqDTO);

    @DeleteMapping(PREFIX + "/delete")
    @Operation(summary = "删除内容")
    @Parameter(name = "id", description = "内容编号", example = "1024", required = true)
    CommonResult<Boolean> deleteContent(@RequestParam("id") Long id);

    @GetMapping(PREFIX + "/get")
    @Operation(summary = "通过内容 ID 查询内容")
    @Parameter(name = "id", description = "内容编号", example = "1024", required = true)
    CommonResult<ContentRespDTO> getContent(@RequestParam("id") Long id);

    @GetMapping(PREFIX + "/list")
    @Operation(summary = "批量查询内容信息")
    @Parameter(name = "ids", description = "内容编号数组", example = "1,2", required = true)
    CommonResult<List<ContentRespDTO>> getContentList(@RequestParam("ids") Collection<Long> ids);

    @GetMapping(PREFIX + "/list-by-container")
    @Operation(summary = "根据容器查询内容列表")
    @Parameter(name = "containerId", description = "容器编号", example = "1", required = true)
    CommonResult<List<ContentRespDTO>> getContentListByContainer(@RequestParam("containerId") Long containerId);

    @GetMapping(PREFIX + "/list-by-author")
    @Operation(summary = "根据作者查询内容列表")
    @Parameter(name = "authorId", description = "作者编号", example = "1024", required = true)
    CommonResult<List<ContentRespDTO>> getContentListByAuthor(@RequestParam("authorId") Long authorId);

    /**
     * 批量查询内容 MAP
     *
     * @param ids 内容编号列表
     * @return 内容 MAP
     */
    default Map<Long, ContentRespDTO> getContentMap(Collection<Long> ids) {
        return convertMap(getContentList(ids).getCheckedData(), ContentRespDTO::getId);
    }

}
